app.controller("blogTypeController", function($scope, $controller,
		blogTypeService) {
	$controller('baseController', {
		$scope : $scope
	});// 继承
	$scope.blogTypeList = [];
	$scope.findTypeList = function(page, rows) {
		blogTypeService.findTypeList(page, rows).success(function(response) {
			$scope.blogTypeList = response.list;
		});
	}

	//查询所有
	$scope.findAll = function(){
		blogTypeService.findAll().success(
				function(response){
					$scope.blogTypeList = response;
				}
		);
	}
	
	$scope.save = function() {
		var methodName = "add";
		if ($scope.entity.typeId != null) {
			methodName = "update";
		}
		blogTypeService.save(methodName, $scope.entity).success(
				function(response) {
					if (response.success) {
						alert(response.message);
						window.location.reload();
					} else {
						alert(response.message)
					}
				});
	}

	// 根据id查询博客类别
	$scope.getBlogTypeById = function(id) {
		blogTypeService.getBlogTypeById(id).success(function(response) {
			$scope.entity = response;
		});
	}

	// 删除
	$scope.del = function() {
		if ($scope.selectIds.length == 0) {
			alert("请勾选删除的对象！！");
			return;
		}
		if (confirm("你确定删除吗？")) {
			blogTypeService.del($scope.selectIds).success(function(response) {
				if (response.success) {
					alert(response.message);
					window.location.reload();
				} else {
					alert(response.message);
				}
			});
		}
	}
	$scope.searchEntity={};
	$scope.search = function(page,rows){
		blogTypeService.search(page,rows,$scope.searchEntity).success(
				function(response){
					$scope.blogTypeList = response.list;
				}
		);
	}
	
	
	$scope.pageInit = function(page, rows){
		blogTypeService.search(page, rows, $scope.searchEntity).success(
				function(response) {
					$scope.blogTypeList = response.list;
					$scope.total = response.total;
					$scope.page($scope.total);
				});
	}
	
	$scope.page = function(total){
		layui.use('laypage', function() {
			var laypage = layui.laypage;
			// 执行一个laypage实例
			laypage.render({
				elem : 'page' // 注意，这里的 test1 是 ID，不用加 # 号
				,
				count : total// 数据总数，从服务端得到
				,
				limit : 4,
				jump : function(obj, first) {
						$scope.search(obj.curr, obj.limit);
				}
			});
		});
	}
});